<template>
    <teleport v-if="isFlashCoupon" to="#BreadcrumbTeleportText">
        <span class="form-tip-color pl15 fz12">*已关联活动/定向发券/会员等级礼/注册送好礼/签到奖励的优惠券不可编辑</span>
    </teleport>

    <g-tabs class="pt12" v-model="params.valuable" :list="tabs" @change="handleChangeTabs">
        <div class="f-e-e f-warp-r pr10">
            <!--优惠券-->
            <div v-if="isFlashCoupon">
                <el-dropdown class="mb10">
                    <el-button type="primary" :icon="Plus">新增优惠券</el-button>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item @click="routerAdd(1)">新增商场券</el-dropdown-item>
                            <el-dropdown-item @click="routerAdd(2)">新增店铺券</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
                <el-button class="ml12 mb10" type="primary" @click="showExportModel({ name: '闪购优惠券概况' })">{{ exportOverviewTitle }}</el-button>
            </div>
            <!--停车券-->
            <div v-if="isParkCoupon">
                <el-dropdown class="mb10">
                    <el-button type="primary" :icon="Plus">新增停车券</el-button>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item @click="routerAdd(1)">免费停车券</el-dropdown-item>
                            <el-dropdown-item>有价停车券</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
                <el-button class="ml12 mb10" type="primary" @click="showExportModel({ name: '停车券概况' })">{{ exportOverviewTitle }}</el-button>
            </div>
            <el-dropdown class="ml12 mb10">
                <el-button type="primary">{{ exportDetailTitle }}&nbsp;
                    <el-icon>
                        <ArrowDown/>
                    </el-icon>
                </el-button>
                <template #dropdown>
                    <el-dropdown-menu>
                        <el-dropdown-item v-for="row in exportDropdownItems" :key="row.id" @click="showExportModel(row)">按{{ row.name }}</el-dropdown-item>
                    </el-dropdown-menu>
                </template>
            </el-dropdown>
            <GFilterTime class="ml12 mb10" :type="componentType" :value="searchParams" @change="mdSearch"/>
            <GSearch class="ml12 mb10" :type="componentType" :value="searchParams" @change="mdSearch"/>
        </div>
    </g-tabs>

    <div class="table-tag-box pt15">
        <el-tag
            v-for="row in filtersStatus"
            :key="row.value"
            class="table-tag-box__item"
            size="default"
            :type="params.status === row.value ? 'primary' : 'info'"
            @click="onClickStatus(row)"
        >
            {{ row.label }}({{ row.count || 0 }})
        </el-tag>
    </div>

    <el-table
        border-t
        v-loading="tableLoading"
        :data="tableData"
        :empty-text="emptyText"
        @sort-change="tableSortChange"
        :default-sort="defaultSort"
        class="table-loading-mask-body"
    >
        <el-table-column fixed="left" property="id" :label="`${isParkCoupon && !isValuable ? '停车' : '优惠'}券ID`" width="100"/>
        <el-table-column
            :label="isParkCoupon && !isValuable ? '券名' : '优惠券名称'"
            width="150"
            fixed="left"
            show-overflow-tooltip
        >
            <template #default="{ row }">{{ row.name || '--' }}</template>
        </el-table-column>
        <el-table-column v-if="isValuable" min-width="100">
            <template #header>
                <GTableHeadSelect name="定价方式" :filters="couponPriceType" v-model="params.price_type" @change="searchStats"/>
            </template>
            <template #default="{ row }">{{ couponPriceTypeLabel[row.item?.price_type] || '--' }}</template>
        </el-table-column>
        <el-table-column min-width="100">
            <template #header>
                <GTableHeadSelect name="券类型" :filters="couponTypes" v-model="params.soule" @change="searchStats"/>
            </template>
            <template #default="{ row }">{{ couponTypesLabel[row.soule] || '--' }}</template>
        </el-table-column>
        <el-table-column v-if="isValuable" label="现价现金部分" min-width="100">
            <template #default="{ row }">{{ row.item?.cash_price || '--' }}</template>
        </el-table-column>
        <el-table-column v-if="isValuable" label="现价积分部分" min-width="100">
            <template #default="{ row }">
                <span v-if="+row.item?.price_type === 2">{{ row.item?.price || 0 }}</span>
                <span v-else>0</span>
            </template>
        </el-table-column>
        <el-table-column v-if="isParkCoupon && !isValuable" label="券详情" min-width="100">
            <template #default="{ row }">
                <span v-if="row.soule === 2">{{ row.off }}折</span>
                <span v-if="row.soule === 4">{{ row.minus }}元</span>
                <span v-if="row.soule === 7">{{ row.free_park_hour }}小时</span>
            </template>
        </el-table-column>
        <el-table-column v-if="isFlashCoupon" min-width="140" show-overflow-tooltip>
            <template #header>
                <GTableHeadSelect
                    name="来源"
                    :props="{ value: 'id', label: 'name' }"
                    inputSearch
                    :filters="shopFilters"
                    v-model="params.shop_id"
                    @change="searchStats"
                />
            </template>
            <template #default="{ row }">{{ row.source || '--' }}</template>
        </el-table-column>
        <el-table-column label="创建者" min-width="150" property="operator" show-overflow-tooltip/>
        <el-table-column property="created_at" label="创建时间" min-width="160"/>
        <el-table-column v-if="isFlashCoupon" min-width="120">
            <template #header>
                <GTableHeadSelect name="适用范围" :filters="couponChannel" v-model="params.channel" @change="searchStats"/>
            </template>
            <template #default="{ row }">{{ couponChannelLabel[row.channel] || '--' }}</template>
        </el-table-column>
        <el-table-column v-if="!isValuable" min-width="110">
            <template #header>
                <GTableHeadSelect name="券用途" :filters="purposeFilters" v-model="params.purpose" @change="searchStats"/>
            </template>
            <template #default="{ row }">{{ purposeFiltersLabel[row.purpose] || '--' }}</template>
        </el-table-column>
        <el-table-column v-if="!isValuable && params.status === 2" min-width="100">
            <template #header>
                <GTableHeadSelect
                    name="关联情况"
                    :filters="[{ label: '已关联', value: 1 }, { label: '未关联', value: 0 }]"
                    v-model="params.used"
                    @change="searchStats"
                />
            </template>
            <template #default="{ row }">
                <span v-if="row.purpose === 1 || row.purpose === 7">--</span>
                <span v-else>{{ row.used === 0 ? '未关联' : '已关联' }}</span>
            </template>
        </el-table-column>
        <el-table-column v-if="!isValuable" label="总发放量" min-width="100" property="num" sortable="custom">
            <template #default="{ row }">
                <span v-if="row.num || row.num === 0">{{ row.num }}</span>
                <span v-else>--</span>
            </template>
        </el-table-column>
        <el-table-column v-if="!isValuable" label="剩余发放量" min-width="120" property="left_num" sortable="custom">
            <template #default="{ row }">
                <span v-if="row.left_num || row.left_num === 0">{{ row.left_num }}</span>
                <span v-else>--</span>
            </template>
        </el-table-column>
        <el-table-column v-if="!isValuable" label="使用量" min-width="100" property="total_verify_num" sortable="custom">
            <template #default="{ row }">
                <span v-if="row.verifyNum || row.verifyNum === 0">{{ row.verifyNum }}</span>
                <span v-else>--</span>
            </template>
        </el-table-column>
        <el-table-column v-if="!isValuable" label="发放时间" min-width="260">
            <template #default="{ row }">
                <span v-if="!row.first_published_at && !row.last_unpublished_at">--</span>
                <div v-else>
                    <span v-if="row.first_published_at">{{ row.first_published_at }}</span>
                    <span v-if="row.first_published_at && row.last_unpublished_at">至</span>
                    <span v-if="row.last_unpublished_at">{{ row.last_unpublished_at }}</span>
                </div>
            </template>
        </el-table-column>
        <el-table-column v-if="isParkCoupon && isValuable" label="总库存" min-width="100" property="num"/>
        <el-table-column v-if="isParkCoupon && isValuable" label="剩余库存" min-width="100" property="left_num"/>
        <el-table-column fixed="right" label="状态" width="80">
            <template #default="{ row }">
                <span :style="{ color: couponStatusColor[row.status] }">{{ couponStatusLabel[row.status] }}</span>
            </template>
        </el-table-column>
        <el-table-column fixed="right" width="290">
            <template #header><span class="pl3">操作</span></template>
            <template #default="{ row }">
                <el-button link type="primary" @click="routerDetail(row)">查看</el-button>
                <el-button v-if="row.showReportBtn" link type="primary" @click="routerReport(row)">报表</el-button>
                <el-button v-if="row.showUpBtn" link type="primary" @click="changeStatus(couponStatusParaphrase.faFangZhong, row.id)">上架</el-button>
                <el-button v-if="row.showDownBtn" link type="primary" @click="showLowerShelvesDialog(row)">下架</el-button>
                <el-button v-if="row.showEditNumBtn" link type="primary" @click="showEditNumber(row)">修改分发量</el-button>
                <el-button v-if="row.showEditBtn" link type="primary" @click="routerEdit(row)">编辑</el-button>

                <el-popover v-if="row.showLinkBtn" placement="bottom" width="160" trigger="hover">
                    <template #reference>
                        <el-button link type="primary" size="small">获取链接</el-button>
                    </template>
                    <div text-c>
                        <el-image class="table-mini-app-code-image" :src="row.miniapp_code"/>
                        <div class="table-mini-app-code-button">
                            <el-button mt10 :disabled="!row.miniapp_code" type="primary" size="small" @click="downloadMiniAppCode(row)">下载二维码</el-button>
                            <el-button mt10 type="primary" size="small" @click="insideCloneLink(row)">{{ isParkCoupon ? '复制活动链接' : '复制微信内推广链接' }}</el-button>
                            <el-button v-if="isFlashCoupon" mt10 type="primary" size="small" @click="outsideCloneLink(row)">复制微信外推广链接</el-button>
                        </div>
                    </div>
                </el-popover>
            </template>
        </el-table-column>
    </el-table>
    <div class="f-d-c pv15">
        <GPagination
            :current-page="params.page"
            :page-size="params.per_page"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
    </div>

    <!--修改库存-->
    <EditNumber v-model="editNumberModel" :detail="couponDetail" @change="getListLoading"/>
    <!--导出-->
    <GExportModel v-model="exportDialogVisible" :config="exportConfig"/>

    <el-dialog v-model="lowerShelvesDialog" title="提示信息" width="270px">
        <div class="text-c pt10 pb15">确认下架吗?</div>
        <template #footer>
            <el-button @click="closeLowerShelvesDialog">取消</el-button>
            <el-button type="primary" :loading="lowerLoading" :disabled="lowerLoading" @click="onLowerShelves">确认</el-button>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
    import { reactive, ref, computed, onMounted } from "vue";
    import { ElMessage } from "element-plus";
    import { ArrowDown, Plus } from "@element-plus/icons-vue";
    import { useRoute, useRouter } from "vue-router";
    import { _mallStore } from "@/store/config";
    import { CouponPurpose } from "@/filters/data";
    import {
        FCouponStatus, FCouponStatusLabel, FCouponStatusColor, FCouponStatusParaphrase,
        FCouponChannel, FCouponChannelLabel,
        FCouponTypes, FCouponTypesLabel, FParkCouponTypes,
        FCouponPriceType, FCouponPriceTypeLabel,
    } from "@/filters";
    import { FilterTimesRow } from "@/components/globalUtils/GFilterTime";
    import { getRestfulV2MallCoupons, getRestfulV2MallCouponStatusStats } from "@/assets/api";
    import { getApiMajorListFilter, outsideCloneLinkApi } from "@/assets/api/handler";
    import { getFiltersDictLabel } from "@/filters/utils";
    import { downloadLink, copyText } from "@/utils";
    import { getCouponTableBtn, handlerCouponListApi, getTableSortOrder, TypeSortParams, TypeTableSort } from "@/utils/handlerData";
    import { $getMountedMdSearch, $setParamsStorage } from "@/utils/storage";
    import { isFlashCouponGroupId, isParkCouponGroupId } from "@/utils/globalTypes";
    import { couponStatusApi } from "@/views/MarketingCenter/utils";
    import { TypeFilters } from "@/interface/filters";
    import { TypeExport } from "@/interface/export";

    import EditNumber from "@/views/MarketingCenter/CouponManage/FlashCoupon/components/EditNumber.vue";

    const route = useRoute();
    const router = useRouter();

    const routeMeta: ObjValueAny = route.meta || {};
    // 闪购优惠券
    const isFlashCoupon = computed(() => {
        return +routeMeta.group_id === isFlashCouponGroupId;
    });
    // 停车优惠券
    const isParkCoupon = computed(() => {
        return +routeMeta.group_id === isParkCouponGroupId;
    });

    let componentType = ref<string>('coupon');
    if (isParkCoupon.value) {
        componentType.value = 'parkCoupon';
    }
    // 券状态
    const filtersStatus = ref<TypeFilters.filter[]>(FCouponStatus);
    const couponStatusLabel = ref<ObjValueStr>(FCouponStatusLabel);
    const couponStatusColor = ref<ObjValueStr>(FCouponStatusColor);
    const couponStatusParaphrase = ref<ObjValueNum>(FCouponStatusParaphrase);
    // 券用途
    const purposeFilters = ref<TypeFilters.filter[]>(CouponPurpose());
    const purposeFiltersLabel = ref<ObjValueStr>(getFiltersDictLabel(purposeFilters.value));
    // 适用范围
    const couponChannel = ref<TypeFilters.filter[]>(FCouponChannel);
    const couponChannelLabel = ref<ObjValueStr>(FCouponChannelLabel);
    // 定价方式
    const couponPriceType = ref<TypeFilters.filter[]>(FCouponPriceType);
    const couponPriceTypeLabel = ref<ObjValueStr>(FCouponPriceTypeLabel);
    // 券类型
    let couponTypes = ref<TypeFilters.filter[]>([]);
    if (isParkCoupon.value) {
        couponTypes.value = FParkCouponTypes;// 停车券
    } else {
        couponTypes.value = FCouponTypes;// 优惠券
    }
    const couponTypesLabel = ref<ObjValueStr>(FCouponTypesLabel);

    const couponThirdTypes: number[] = [1];// 免费券
    const valuableThirdTypes: number[] = [1, 3];// 有价券（包括第三方卡券）
    let emptyText = ref<string>('');
    let tableLoading = ref<boolean>(false);
    let tableData = ref<ObjValueAny[]>([]);
    let total = ref<number>(0);
    let searchParams = reactive<ObjValueStr>({});
    let params = reactive<ObjValueAny>({
        page: 1,
        per_page: 15,
        valuable: 0,
        statuses: [0, 1, 2, 3, 4, 5, 8],
        status: '',
        soule: '',
        shop_id: '',
        channel: '',
        purpose: '',
        origin: '',
        price_type: '',
        order: '',
        sort: '',
        used: '',
    });
    if (isParkCoupon.value) {
        params.group_id = routeMeta.group_id;
    } else {
        params.third_types = couponThirdTypes;
    }

    // 免费券/有价券
    const tabs = reactive<ObjValueAny>([
        { value: 0, label: '免费券', count: 0 },
        { value: 1, label: '有价券', count: 0 },
    ]);
    // 有价券
    const isValuable = computed(() => {
        return params.valuable === 1;
    })

    onMounted(() => {
        $getMountedMdSearch(componentType.value, params, searchParams);
        defaultSort.value.prop = params.order || '';
        defaultSort.value.order = params.sort ? `${params.sort}ending` : '';
        getTableList();
        getShopList();
        gtCouponValuableStats();
        getListStats().then((resp: ObjValueAny) => {
            if (resp.code === 200) {
                for (let row of resp.data) {
                    if (+row.status === 0 && row.total > 0) {
                        ElMessage({
                            message: `您有${row.total}个优惠券待审核`,
                            type: 'warning',
                            offset: 40,
                            duration: 2000
                        });
                    }
                }
            }
        })
    })

    // 店铺筛选
    const shopFilters = ref<ObjValueAny[]>([]);
    const getShopList = async () => {
        shopFilters.value = await getApiMajorListFilter();
    }

    const searchStats = () => {
        resetPageTableList();
        getListStats();
    }
    // 免费券/有价券 切换
    const handleChangeTabs = (id: number) => {
        params.purpose = '';
        params.price_type = '';
        params.status = '';
        params.valuable = id;
        if (isFlashCoupon.value) {
            if (isValuable.value) {
                params.third_types = valuableThirdTypes;
            } else {
                params.third_types = couponThirdTypes;
            }
        }
        searchStats();
    }
    // 状态筛选
    const onClickStatus = (row: TypeFilters.filter) => {
        params.status = row.value;
        resetPageTableList();
    }
    // 排序
    const defaultSort = ref<TypeTableSort>({ prop: '', order: '' });
    const tableSortChange = ({ order, prop }: TypeTableSort) => {
        const paramsSort: TypeSortParams = getTableSortOrder(order, prop);
        params.order = paramsSort.order_by;
        params.sort = paramsSort.sort;
        resetPageTableList();
    }
    // 日期/关键字 搜索
    const mdSearch = (row: FilterTimesRow) => {
        searchParams = Object.assign(searchParams, row);
        resetPageTableList();
    }
    const resetPageTableList = () => {
        handleCurrentChange();
    }
    // 选择 每页条数
    const handleSizeChange = (num: number) => {
        params.per_page = num;
        resetPageTableList();
    }
    // 分页
    const handleCurrentChange = (page: number = 1) => {
        params.page = page;
        getListLoading();
    }
    // 列表请求 loading
    const getListLoading = () => {
        tableLoading.value = true;
        gtCouponValuableStats();
        getTableList();
    }
    // 会员列表
    const getTableList = () => {
        emptyText.value = '加载中...';
        const storeParams: ObjValueAny = { ...params };
        if (storeParams.valuable === 0) {
            delete storeParams.price_type;
        }
        getRestfulV2MallCoupons({ ...storeParams, ...searchParams }, { noRepeat: 1 }).then((resp: ObjValueAny) => {
            if (resp.code === 200) {
                const { data } = resp;
                for (let row of data) {
                    handlerCouponListApi(row);
                    getCouponTableBtn(row, storeParams.valuable);
                }
                tableData.value = data;
                total.value = resp.meta?.total || 0;
            } else {
                ElMessage.error(resp.msg);
            }
            emptyText.value = '暂无数据';
            tableLoading.value = false;
        })
    }
    // 获取统计数据
    const getListStats = (): Promise<ObjValueAny> => {
        return new Promise(async resolve => {
            const statsParams: ObjValueAny = {
                shop_id: params.shop_id,
                origin: params.origin,
                soule: params.soule,
                channel: params.channel,
                purpose: params.purpose,
                statuses: params.statuses,
                valuable: params.valuable,
                third_types: params.third_types,
                ...searchParams,
            };
            if (isParkCoupon.value) {
                statsParams.group_id = params.group_id;
            }
            if (isValuable.value) {
                statsParams.price_type = params.price_type;
            }
            getRestfulV2MallCouponStatusStats(statsParams, { noRepeat: 1 }).then((resp: ObjValueAny) => {
                if (resp.code === 200) {
                    const { data } = resp;
                    const _statsDict: ObjValueAny = {};
                    for (let row of data) {
                        if (row.status === -1) {
                            _statsDict[''] = row.total;
                        } else {
                            _statsDict[row.status] = row.total;
                        }
                    }
                    for (let row of filtersStatus.value) {
                        row.count = _statsDict[row.value] || 0;
                    }
                    resolve(resp)
                } else {
                    ElMessage.error(resp.msg);
                    resolve({});
                }
            });
        })
    }
    // 免费券/有价券 统计
    const gtCouponValuableStats = () => {
        const valuableStatsParams: ObjValueAny = {
            page: 1,
            per_page: 0,
            valuable: 0,
            statuses: params.statuses,
            shop_id: params.shop_id,
            origin: params.origin,
            soule: params.soule,
            channel: params.channel,
            purpose: params.purpose,
            ...searchParams
        };
        if (isParkCoupon.value) {
            valuableStatsParams.group_id = params.group_id;
        }
        // 免费券总条数 ============================
        if (isFlashCoupon.value) {
            valuableStatsParams.third_types = couponThirdTypes;
        }
        getRestfulV2MallCoupons({ ...valuableStatsParams, ...searchParams }).then((resp: ObjValueAny) => {
            tabs[0].count = resp.meta?.total || 0;
        })
        // 有价券总条数 ============================
        valuableStatsParams.purpose = '';
        valuableStatsParams.valuable = 1;
        valuableStatsParams.price_type = params.price_type;
        if (isFlashCoupon.value) {
            valuableStatsParams.third_types = valuableThirdTypes;
        }
        getRestfulV2MallCoupons({ ...valuableStatsParams, ...searchParams }).then((resp: ObjValueAny) => {
            tabs[1].count = resp.meta?.total || 0;
        })
    }

    // 新增
    const routerAdd = (origin: number) => {
        setStorageParams();
        routerEdit({ origin })
    }
    // 编辑
    const routerEdit = (row: ObjValueAny = {}) => {
        setStorageParams();
        const query: ObjValueAny = {};
        if (row.id) {
            query.id = row.id;
        }
        router.push({
            name: `${isParkCoupon.value ? 'ParkCouponEdit' : 'CouponEdit'}`,
            params: { origin: row.origin, group_id: +routeMeta.group_id },
            query,
        })
    }
    // 查看
    const routerDetail = (row: ObjValueAny = {}) => {
        setStorageParams();
        router.push({
            name: `${isParkCoupon.value ? 'ParkCouponDetail' : 'CouponDetail'}`,
            params: { id: row.id, origin: row.origin, group_id: +routeMeta.group_id }
        })
    }
    // 报表
    const routerReport = (row: ObjValueAny = {}) => {
        setStorageParams();
        router.push({
            name: `${isParkCoupon.value ? 'ParkCouponReport' : 'CouponReport'}`,
            params: { id: row.id, origin: row.origin, group_id: +routeMeta.group_id }
        })
    }
    const setStorageParams = () => {
        $setParamsStorage({
            ...params,
            ...searchParams,
        })
    }
    // 修改分发量
    const editNumberModel = ref<boolean>(false);
    const couponDetail = ref<ObjValueAny>({});
    const showEditNumber = (row: ObjValueAny) => {
        couponDetail.value = row;
        editNumberModel.value = true;
    }
    // 下架
    let lowerShelvesDialog = ref<boolean>(false);
    let lowerLoading = ref<boolean>(false);
    const showLowerShelvesDialog = (row: ObjValueAny) => {
        lowerShelvesDialog.value = true;
        lowerLoading.value = false;
        couponDetail.value = row;
    }
    const closeLowerShelvesDialog = () => {
        lowerShelvesDialog.value = false;
    }
    const onLowerShelves = () => {
        lowerLoading.value = true;
        changeStatus(couponStatusParaphrase.value.xiaJiaZhong, couponDetail.value.id);
    }
    // 上架/下架
    const changeStatus = async (status: number, id: number) => {
        tableLoading.value = true;
        const code: number = await couponStatusApi({ status }, id);
        if (code === 200) {
            closeLowerShelvesDialog();
            searchStats();
        } else {
            lowerLoading.value = false;
        }
    }
    // 下载二维码
    const downloadMiniAppCode = (row: ObjValueAny) => {
        downloadLink(row.miniapp_code);
    }
    // 复制微信内推广链接
    const insideCloneLink = (row: ObjValueAny) => {
        let url: string, { conglomeration } = row;
        if (isValuable.value) {
            if (conglomeration && conglomeration.id) {
                url = `pages/assembleDetail/index?mall_id=${_mallStore.mallId}&id=${row.conglomeration.id}`;
            } else {
                url = `pages/falshDetail/index?mall_id=${_mallStore.mallId}&id=${row.item?.id}`;
            }
        } else {
            url = `pages/couponDetail/index?mall_id=${_mallStore.mallId}&couponid=${row.id}`;
        }
        copyText(url);
    }
    // 复制微信外推广链接
    const outsideCloneLink = (row: ObjValueAny) => {
        let type: string = 'coupon';
        if (isValuable.value) {
            const rowType = isValuable.value ? row.item.type : row.type;
            if (rowType === 2) {
                type = 'conglomeration';
            }
            if (rowType === 3) {
                type = 'item';
            }
        }
        outsideCloneLinkApi({ type, id: isValuable.value ? row.item.id : row.id });
    }

    // 导出
    const exportOverviewTitle = computed(() => {
        return isParkCoupon.value ? '导出停车券概况' : '导出优惠券概况';
    })
    const exportDetailTitle = computed(() => {
        return isParkCoupon.value ? '导出停车券明细' : '导出优惠券明细';
    })
    const exportDropdownItems = reactive<TypeFilters.filterApi[]>([
        { id: 6, name: '获得时间' },
        { id: 3, name: '核销时间' },
    ]);

    let exportDialogVisible = ref<boolean>(false);
    const exportConfig = reactive<TypeExport.Config>({
        body: {
            keyword: 'coupons_data',
            group_id: routeMeta.type,
        },
    });
    const showExportModel = (row: ObjValueAny = {}) => {
        if (row.id) {
            exportConfig.condition = row.name;
            exportConfig.title = exportDetailTitle.value;
            exportConfig.body!.export_mode = isParkCoupon.value ? 3 : 1;
            exportConfig.content = { name: row.name };
            exportConfig.name = '闪购优惠券总领取明细';
            exportConfig.body!.export_type = row.id;
        } else {
            exportConfig.condition = '创建时间';
            exportConfig.name = row.name;
            exportConfig.title = exportOverviewTitle.value;
            exportConfig.body!.statuses = params.statuses;
            exportConfig.content = { name: exportConfig.condition };
        }
        exportDialogVisible.value = true;
    }
</script>

<style scoped lang="scss">
    @import "@/styles/components/list.scss";
</style>